package com.cicadamob.contact.api.Utils;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.os.Environment;
import android.telephony.TelephonyManager;
import android.text.TextUtils;

import com.cicadamob.contact.api.Utils.Data.SharedPreferencesUtil;
import com.cicadamob.contact.api.service.ServerUrl;
import com.gmcc.gz.http_wmmp.bean.HostBean;
import com.gmcc.gz.http_wmmp.config.ConfigManager_httpwmmp;
import com.gmcc.gz.http_wmmp.config.ServerUrl_httpWmmp.HostNetype;

/**
 * Created by yeyue on 2014-10-8.
 */
@SuppressLint("NewApi")
public class ContactConfig {
	private static Application mContext;
	/** 个人中心ip */
	private static final String PERSON_CENTER_IPPORT73 = "183.232.32.73:8181";
	private static final String PERSON_CENTER_IPPORT102 = "183.232.65.102:8181";
	private static final String PERSON_CENTER_IPPORT_SIP22="120.236.156.22:8181";
	public static  String PERSON_CENTER_IPPORT=PERSON_CENTER_IPPORT73;

	/** 存储中心ip */
	private static final String STORAGE_IP73 = "192.168.1.31:8182";
	private static final String STORAGE_IP102 = "183.232.65.102:8182";
	private static final String STORAGE_SIP_IP22 = "120.236.156.22:8182";
	public static final String STORAGE_IP = STORAGE_IP73;



	public static final String downUrl = "http://" + STORAGE_IP
			+ "/imp/mediaController/download.htm";
	public static final String uploadUrl = "http://" + STORAGE_IP
			+ "/imp/mediaController/upload.htm";
	public static String WEBSERVER = "183.232.32.73";
//	 public static String WEBSERVER = "183.232.65.102" ;
//	 public static String WEBSERVER = "120.236.156.22" ;
	/** 自维通讯录 fromid **/
	public static final String editContactId = "999999999";

	private ContactConfig() {

	}

	public static final boolean DEBUG = false;

	public static final String Sp_LoginName = "Sp_LoginName";

	/** 是否登陆 **/
	public static final String Sp_Logined = "Sp_Logined";
	/*** 企业id */
	public static final String Sp_EcId = "Sp_EcId";
	/** 旧的手机号 **/
	public static final String Sp_OlderPhone = "Sp_OlderPhone";
	/** 百度推送channelid **/
	public static final String Sp_BaiduChannelId = "Sp_BaiduChannelId";
	/** 百度推送userid **/
	public static final String Sp_BaiduUserlId = "Sp_BaiduUserlId";
	/** socketpush ip **/
	public static final String Sp_socketPushIP = "Sp_socketPushIP";
	/** socketpush port **/
	public static final String Sp_socketPushPort = "Sp_socketPushPort";
	/** 用户姓名 **/
	public static final String Sp_userName = "Sp_userName";
	/** 用户声音Url **/
	public static final String Sp_userSoundUrl = "Sp_userSoundUrl";
	/** 用户声音Url **/
	public static final String Sp_userSoundTime = "Sp_userSoundTime";
	// 程序数据保存目录
	public static final String HEAD_DIRECTORY = "/ManagerAssistant";
	public static final String DIRECTORY = Environment
			.getExternalStorageDirectory().getAbsolutePath() + HEAD_DIRECTORY;
	/** 默认企业id 个人(无企业id) **/
	public static String DEFAULT_EC_ID = "-999998";
	/**
	 * 百度地图悬浮参数
	 * 
	 */
	public static String BAIDUMAP_PARCELABLE = "baiDuMapParcelable";
	/**
	 * 百度地图确定按钮
	 * 
	 */
	public static String BAIDUMAP_SUBMIT = "baiDuMapSubmit";
	/**
	 * 百度地图需要要强调显示位置数目
	 * 
	 */
	public static String BAIDUMAP_COUNT = "baiDuMapCount";

	/** 获取get domain URL **/
	public static final String GET_HOST_URL = "GET_HOST_URL";
	
	/**
	 * 一个广播
	 */
	public static final String ContentType_ACTION="com.gmccgz.kakaonew.Location.fragment.ContentTypeFragment";

	/**
	 * 设置sdk的ip和端口
	 * @param ip 
	 * @param post端口
	 */
	public static void setConfigIp(String ip,String post){
		ContactConfig.PERSON_CENTER_IPPORT=ip+":"+post;
		WEBSERVER=ip;
	}
	/**
	 * 获取token
	 * 
	 * @param context
	 * @return
	 */
	public static String getToken(Context context) {
		// return SharedPreferencesUtil.getString(context, Sp_Token,"");
		return ConfigManager_httpwmmp.getToken(context);
	}

	/**
	 * getSDcardCachePath
	 * 
	 * @param context
	 * @return
	 */
	public static String getSDcardCachePath(Context context) {
		return context.getExternalCacheDir().getAbsolutePath();
	}

	/**
	 * 获取登陆手机号码
	 * 
	 * @param context
	 * @return
	 */
	public static String getMobile(Context context) {
		
		return SharedPreferencesUtil.getString(context, "sp_mobile","");
//		return ConfigManager_httpwmmp.getPhone(context);
	}

	/**
	 * 获取百度推送channelid
	 * 
	 * @param context
	 * @return
	 */
	public static String getBaiduChannelId(Context context) {
		return SharedPreferencesUtil.getString(context, Sp_BaiduChannelId, "");
	}

	/**
	 * 获取百度推送userid
	 * 
	 * @param context
	 * @return
	 */
	public static String getBaiduUserId(Context context) {
		return SharedPreferencesUtil.getString(context, Sp_BaiduUserlId, "");
	}

	/**
	 * 获取imei
	 * 
	 * @param context
	 * @return
	 */
	public static String getIMEI(Context context) {
		// return SharedPreferencesUtil.getString(context, Sp_IMEI,"");
		return ConfigManager_httpwmmp.getIMEI(context);
	}

	/**
	 * 获取IMSI
	 * 
	 * @param context
	 * @return
	 */
	public static String getIMSI(Context context) {
		// return SharedPreferencesUtil.getString(context, Sp_IMSI,"");
		String imsi = ConfigManager_httpwmmp.getIMSI(context);
		if (TextUtils.isEmpty(imsi)) {
			TelephonyManager tm = (TelephonyManager) context
					.getSystemService(Context.TELEPHONY_SERVICE);
			imsi = tm.getSubscriberId();
		}
		return imsi;
	}

	/**
	 * 是否已经登陆
	 * 
	 * @return
	 */
	public static boolean isLogined(Context mContext) {
		return SharedPreferencesUtil.getBoolean(mContext, ContactConfig.Sp_Logined,
				false);
	}

	/**
	 * 设置是否登陆
	 * 
	 * @param mContext
	 * @param isLogined
	 */
	public static void setLogined(Context mContext, boolean isLogined) {
		SharedPreferencesUtil.putBoolean(mContext, ContactConfig.Sp_Logined,
				isLogined);
	}

	/**
	 * 获取企业id
	 * 
	 * @param context
	 * @return
	 */
	public static String getEc_id(Context context) {
		String ec_id = "";
		ec_id = SharedPreferencesUtil
				.getString(context, Sp_EcId, DEFAULT_EC_ID);
		return ec_id;
	}

	/**
	 * 注销的时候清空企业id
	 * 
	 * @param context
	 */
	public static void clear_Ec_id(Context context) {
		SharedPreferencesUtil.getString(context, Sp_EcId, DEFAULT_EC_ID);
	}

	/**
	 * 保存socket_push ip和port
	 * 
	 * @param context
	 * @param ip
	 * @param port
	 */
	public static void saveSocketPushIpAndPort(Context context, String ip,
			int port) {
		SharedPreferencesUtil.putString(context, Sp_socketPushIP, ip);
		SharedPreferencesUtil.putInt(context, Sp_socketPushPort, port);

	}

	/**
	 * 获取socket_push ip
	 * 
	 * @param context
	 * @return
	 */
	public static String getSocketPushIp(Context context) {
		return SharedPreferencesUtil.getString(context, Sp_socketPushIP, "");
	}

	/**
	 * 获取sockt_push port
	 * 
	 * @param context
	 * @return
	 */
	public static int getSocketPushPort(Context context) {
		return SharedPreferencesUtil.getInt(context, Sp_socketPushPort, 0);
	}

	/**
	 * 设置各模块网元的ip和port netype：网元类型， 包括如下取值 socket：socket组件 imp：消息中心 ctrl：控制平台
	 * contact：通讯录 storage：存储中心 group：群组 task：任务 information：资讯
	 * 
	 * 
	 * 如不需要做保存处理 可直接通过 ConfigManager_httpwmmp.getHostUrl(context, HostNetype.类型)
	 * 获取相应的ip/port
	 * 
	 */
	public static void setHostDomain(Context context) {
//		HostBean bean = new HostBean();
//		String ip = "";
//		int port = 0;
//		// 1、控制平台
//		bean = ConfigManager_httpwmmp.getHostUrl(context, HostNetype.ctrl);
//		ip = bean.getIP();
//		port = bean.getPort();
//		bean.getHostUrl();// http:// ip : port;
//		// todo something
//		// 临时用 等后台配置好后 删除
//		ConfigManager_httpwmmp.saveCtrlHostUrl(context,
//				ServerUrl.Ctrl_host_host);
//
//		// 2、socket组件
//		bean = ConfigManager_httpwmmp.getHostUrl(context, HostNetype.socket);
//		ip = bean.getIP();
//		port = bean.getPort();
//		bean.getHostUrl(); // http:// ip : port;
//		// 保存ip/port
//		saveSocketPushIpAndPort(context, ip, port);
//
//		// 3、消息中心
//		bean = ConfigManager_httpwmmp.getHostUrl(context, HostNetype.imp);
//		ip = bean.getIP();
//		port = bean.getPort();
//		bean.getHostUrl(); // http:// ip : port;
//		// to do something
//
//		// 4、通讯录
//		bean = ConfigManager_httpwmmp.getHostUrl(context, HostNetype.contact);
//		ip = bean.getIP();
//		port = bean.getPort();
//		bean.getHostUrl(); // http:// ip : port;
//		// to do something
//
//		// 5、存储中心
//		bean = ConfigManager_httpwmmp.getHostUrl(context, HostNetype.storage);
//		ip = bean.getIP();
//		port = bean.getPort();
//		bean.getHostUrl(); // http:// ip : port;
//		// to do something
//
//		// 6、 ：群组
//		bean = ConfigManager_httpwmmp.getHostUrl(context, HostNetype.group);
//		ip = bean.getIP();
//		port = bean.getPort();
//		bean.getHostUrl(); // http:// ip : port;
//		// to do something
//
//		// 7、：任务
//		// bean=ConfigManager_httpwmmp.getHostUrl(context, HostNetype.task);
//		// ip=bean.getIP();
//		// port=bean.getPort();
//		// bean.getHostUrl(); // http:// ip : port;
//		// to do something
//
//		// 8、：资讯
//		bean = ConfigManager_httpwmmp.getHostUrl(context,
//				HostNetype.information);
//		ip = bean.getIP();
//		port = bean.getPort();
//		bean.getHostUrl(); // http:// ip : port;
		// to do something
	}

	

	/**
	 * 获取用户姓名
	 * 
	 * @param context
	 * @return
	 */
	public static String getUserName(Context context) {
		return SharedPreferencesUtil.getString(context, Sp_userName, "");
	}

	/**
	 * 保存用户姓名
	 * 
	 * @param context
	 * @param userName
	 */
	public static void saveUserName(Context context, String userName) {
		SharedPreferencesUtil.putString(context, Sp_userName, userName);
	}

	/**
	 * 获取用户媒体声音url
	 * 
	 * @param context
	 * @return
	 */
	public static String getUserSoundUrl(Context context) {
		return SharedPreferencesUtil.getString(context, Sp_userSoundUrl, "");
	}

	/**
	 * 保存用户媒体声音URL
	 * 
	 * @param context
	 * @param userName
	 */
	public static void saveUserSoundUrl(Context context, String userName) {
		SharedPreferencesUtil.putString(context, Sp_userSoundUrl, userName);
	}

	/**
	 * 获取用户媒体声音时长
	 * 
	 * @param context
	 * @return
	 */
	public static String getUserSoundTime(Context context) {
		return SharedPreferencesUtil.getString(context, Sp_userSoundTime, "");
	}

	/**
	 * 保存用户媒体声音时长
	 * 
	 * @param context
	 * @param userName
	 */
	public static void saveUserSoundTime(Context context, String userName) {
		SharedPreferencesUtil.putString(context, Sp_userSoundTime, userName);
	}

	/**
	 * 保存获取 domain url
	 * 
	 * @param context
	 * @param url
	 */
	public static void saveGetHostUrl(Context context, String url) {
		SharedPreferencesUtil.putString(context, GET_HOST_URL, url);
	}

	/**
	 * 获取 domain url
	 * 
	 * @param context
	 * @return
	 */
	public static String getHostUrl(Application context) {
		return SharedPreferencesUtil.getString(context, GET_HOST_URL, "");

	}
	
	public static String getCompanyValidVCode(Context context) {
		return SharedPreferencesUtil.getString(context, "COMPANY_VALID_VCODE", "");
	}
	
	public static String getCompanyValidMobile(Context context) {
		return SharedPreferencesUtil.getString(context, "COMPANY_VALID_MOBILE", "");
	}

	public static String getCompanyValidCompanyId(Context context) {
		return SharedPreferencesUtil.getString(context, "COMPANY_VALID_CMPANYID", "");
	}
	
	public static Application getContext() {
		return mContext;
	}

	public static void setContext(Application mContext) {
		ContactConfig.mContext = mContext;
	}
	
}
